Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AI Chat] fix issues with conversation context menu #26990

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

petemill
Copy link
Member

@petemill petemill commented Dec 12, 2024

  • Menu open too small and has scroll inside when there's only 1 conversation list item
  • Opening a menu when hovering causes the list item to be clicked (the link to be followed)
  • Editing the title was impossible because the action was cancelled when navigating

Blocked on:

Resolves

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

@petemill petemill self-assigned this Dec 12, 2024
@petemill petemill requested a review from a team as a code owner December 12, 2024 01:03
@github-actions github-actions bot added CI/run-audit-deps Check for known npm/cargo vulnerabilities (audit_deps) CI/storybook-url Deploy storybook and provide a unique URL for each build labels Dec 12, 2024
Copy link
Contributor

@fallaciousreasoning fallaciousreasoning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm assuming Nala bump is separated

conversation->title = title;
void AIChatService::OnConversationTitleChanged(
const std::string& conversation_uuid,
const std::string& new_title) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this just take a std::string so we can move the new_title into this function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed in the slack thread, doesn't seem like it's worth the optimization

Comment on lines +815 to +829
auto& conversation_metadata = conversation_it->second;
conversation_metadata->title = new_title;

OnConversationListChanged();

// Persist the change
if (ai_chat_db_) {
ai_chat_db_
.AsyncCall(base::IgnoreResult(&AIChatDatabase::UpdateConversationTitle))
.WithArgs(handler->get_conversation_uuid(), std::move(title));
.WithArgs(conversation_uuid, new_title);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we just take a std::string:

Suggested change
auto& conversation_metadata = conversation_it->second;
conversation_metadata->title = new_title;
OnConversationListChanged();
// Persist the change
if (ai_chat_db_) {
ai_chat_db_
.AsyncCall(base::IgnoreResult(&AIChatDatabase::UpdateConversationTitle))
.WithArgs(handler->get_conversation_uuid(), std::move(title));
.WithArgs(conversation_uuid, new_title);
auto& conversation_metadata = conversation_it->second;
conversation_metadata->title = std::move(new_title);
OnConversationListChanged();
// Persist the change
if (ai_chat_db_) {
ai_chat_db_
.AsyncCall(base::IgnoreResult(&AIChatDatabase::UpdateConversationTitle))
.WithArgs(conversation_uuid, conversation_metadata->title);

@@ -1685,7 +1685,7 @@ void ConversationHandler::OnClientConnectionChanged() {

void ConversationHandler::OnConversationTitleChanged(std::string title) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this take a const std::string& or a string_view? It's not doing anything async

@@ -1685,7 +1685,7 @@ void ConversationHandler::OnClientConnectionChanged() {

void ConversationHandler::OnConversationTitleChanged(std::string title) {
for (auto& observer : observers_) {
observer.OnConversationTitleChanged(this, title);
observer.OnConversationTitleChanged(metadata_->uuid, title);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is a const std::string&

const [isButtonMenuVisible, setIsButtonMenuVisible] = React.useState(false)
const [isOptionsMenuOpen, setIsOptionsMenuOpen] = React.useState(false)

const handleButtonMenuChange = React.useCallback((e: {isOpen: boolean}) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: with stuff like this where you're at a leaf node, I think its okay to not wrap things in a useCallback (or do it inline)

Up to you on this one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wasn't sure if our web component would cause a new listener to be added (and the old one removed) on every single render. But I suppose we're doing that everywhere anyway

Copy link
Contributor

@fallaciousreasoning fallaciousreasoning Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will 😆 - but its the same with every other component that does this so 🤷

And with React compiler it will (probably) Just Work (tm)

className={styles.displayTitle}
onMouseEnter={() => setIsButtonMenuVisible(true)}
onMouseLeave={() => setIsButtonMenuVisible(false)}
className={classnames(styles.displayTitle, isOptionsMenuOpen && styles.isOptionsMenuOpen)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a handy util taher added!

@@ -28,11 +28,11 @@ function SearchSummary (props: { searchQueries: string[] }) {
const message = formatMessage(getLocale('searchQueries'), {
placeholders: {
$1: props.searchQueries.map((query, i, a) => (
<>
<React.Fragment key={i}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 you're a hero - these errors drive me nuts

// Unknown events should be ignored
return null
}

export default function AssistantResponse(props: { entry: Mojom.ConversationTurn, isEntryInProgress: boolean }) {
const searchQueriesEvent = props.entry.events?.find(event => !!event.searchQueriesEvent)?.searchQueriesEvent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

superfluous !!

Suggested change
const searchQueriesEvent = props.entry.events?.find(event => !!event.searchQueriesEvent)?.searchQueriesEvent
const searchQueriesEvent = props.entry.events?.find(event => event.searchQueriesEvent)?.searchQueriesEvent

export default function AssistantResponse(props: { entry: Mojom.ConversationTurn, isEntryInProgress: boolean }) {
const searchQueriesEvent = props.entry.events?.find(event => !!event.searchQueriesEvent)?.searchQueriesEvent
const hasCompletionStarted = !props.isEntryInProgress || props.entry.events?.find(event => !!event.completionEvent)
const hasCompletionStarted = !props.isEntryInProgress ||
(props.entry.events?.some(event => !!event.completionEvent) ?? false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

superfluous !!

Suggested change
(props.entry.events?.some(event => !!event.completionEvent) ?? false)
(props.entry.events?.some(event => event.completionEvent) ?? false)

optional:

Suggested change
(props.entry.events?.some(event => !!event.completionEvent) ?? false)
const hasCompletionStarted = props.isEntryInProgress
|| !!props.entry.events?.some(e => e.completionEvent)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been studying this for a good few minutes and I still can't quickly reason with the names here, or how your suggestion is equivalent to what's there at the moment. Not introduced in this PR but I think we can improve it at some point.

@petemill petemill force-pushed the ai-chat-untrusted-frame branch from ce3b00c to 84b6868 Compare December 12, 2024 03:52
@petemill petemill requested review from a team and bridiver as code owners December 12, 2024 03:52
@petemill
Copy link
Member Author

petemill commented Dec 12, 2024

Ignore this, it needs a rebase

@petemill petemill removed request for a team and bridiver December 12, 2024 06:16
Base automatically changed from ai-chat-untrusted-frame to master December 12, 2024 06:42
@petemill petemill force-pushed the ai-chat-menu-fixes branch 4 times, most recently from 8cd1e4c to f086917 Compare December 12, 2024 22:39
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@petemill petemill force-pushed the ai-chat-menu-fixes branch 2 times, most recently from 1e12113 to 0f6e891 Compare December 13, 2024 06:05
@petemill petemill enabled auto-merge December 13, 2024 06:14
@petemill petemill disabled auto-merge December 13, 2024 08:43
- ButtonMenu can open without being tiny and scrolling
- make sure edit isn't blocked by the link activation
- storybook get edit ability
and log database title because of historical bad values due to ref expiring
storybook context can use react hooks
@petemill petemill enabled auto-merge December 13, 2024 09:17
@petemill petemill disabled auto-merge December 13, 2024 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/run-audit-deps Check for known npm/cargo vulnerabilities (audit_deps) CI/storybook-url Deploy storybook and provide a unique URL for each build
Projects
None yet
3 participants